import { defineStore } from 'pinia'
import { store } from '/@/store'
import type { AxiosResponse } from 'axios'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import staffService from '/@/api/cn/core/sign/staffService'

import type { Staff } from '/@/model/cn/core/sign/eo/Staff'
import type { StaffQO } from '/@/model/cn/core/sign/qo/StaffQO'
import type { StaffVO } from '/@/model/cn/core/sign/vo/StaffVO'

interface StaffState {
}

export const useStaffStore = defineStore({
  id: 'staff',
  state: (): StaffState => ({
  }),
  getters: {
  },
  actions: {
    save(param: Param<StaffVO>): Promise<Res<StaffVO>> {
      return new Promise<Res<StaffVO>>((resolve, reject) => {
        staffService.save(param).then((res: AxiosResponse<Res<StaffVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    saveBatch(param: Param<Staff>): Promise<Res<Staff>> {
      return new Promise<Res<Staff>>((resolve, reject) => {
        staffService.saveBatch(param).then((res: AxiosResponse<Res<Staff>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    update(param: Param<StaffVO>): Promise<Res<StaffVO>> {
      return new Promise<Res<StaffVO>>((resolve, reject) => {
        staffService.update(param).then((res: AxiosResponse<Res<StaffVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    updateBatch(param: Param<Staff>): Promise<Res<Staff>> {
      return new Promise<Res<Staff>>((resolve, reject) => {
        staffService.updateBatch(param).then((res: AxiosResponse<Res<Staff>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    remove(param: Param<Staff>): Promise<Res<Staff>> {
      return new Promise<Res<Staff>>((resolve, reject) => {
        staffService.remove(param).then((res: AxiosResponse<Res<Staff>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    removeBatch(param: Param<Staff>): Promise<Res<Staff>> {
      return new Promise<Res<Staff>>((resolve, reject) => {
        staffService.removeBatch(param).then((res: AxiosResponse<Res<Staff>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    count(param: Param<StaffQO>): Promise<Res<Staff>> {
      return new Promise<Res<Staff>>((resolve, reject) => {
        staffService.count(param).then((res: AxiosResponse<Res<Staff>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pk(param: Param<StaffQO>): Promise<Res<Staff>> {
      return new Promise<Res<Staff>>((resolve, reject) => {
        staffService.pk(param).then((res: AxiosResponse<Res<Staff>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    query(param: Param<StaffQO>): Promise<Res<Staff>> {
      return new Promise<Res<Staff>>((resolve, reject) => {
        staffService.query(param).then((res: AxiosResponse<Res<Staff>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    paging(param: Param<StaffQO>): Promise<Res<Staff>> {
      return new Promise<Res<Staff>>((resolve, reject) => {
        staffService.paging(param).then((res: AxiosResponse<Res<Staff>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    countVo(param: Param<StaffQO>): Promise<Res<StaffVO>> {
      return new Promise<Res<StaffVO>>((resolve, reject) => {
        staffService.countVo(param).then((res: AxiosResponse<Res<StaffVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pkVo(param: Param<StaffQO>): Promise<Res<StaffVO>> {
      return new Promise<Res<StaffVO>>((resolve, reject) => {
        staffService.pkVo(param).then((res: AxiosResponse<Res<StaffVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    queryVo(param: Param<StaffQO>): Promise<Res<StaffVO>> {
      return new Promise<Res<StaffVO>>((resolve, reject) => {
        staffService.queryVo(param).then((res: AxiosResponse<Res<StaffVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pagingVo(param: Param<StaffQO>): Promise<Res<StaffVO>> {
      return new Promise<Res<StaffVO>>((resolve, reject) => {
        staffService.pagingVo(param).then((res: AxiosResponse<Res<StaffVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
  },
})

export function useStaffStoreWithout() {
  return useStaffStore(store)
}
